<?php
include("utils.php");

if($_SESSION['siteuserId']==""){
    header("location:start.php");
}
if($_POST['mode']=="change_status"){
    change_status();
}
else if($_POST['mode']=="delete_site"){
    delete_site();
}
else{
    main_content("main();");
}

function delete_site(){
    $SQL_delete="delete from ".SITEMASTER." where adsiteId = '".$_POST['siteId']."'";
    mysql_query($SQL_delete);
    main_content("main();");
}

function change_status(){
    $sql = "UPDATE ".SITEMASTER." SET status = if(status = 'N','Y','N') WHERE adsiteId = '".$_POST['Id']."' ";
    mysql_query($sql);
    $GLOBALS['err_msg']=STATUS_SUCCESS_CHANGE;
    main_content("main();");
}

function main(){
    if($_SESSION['languageId']!=""){
        $languageId=$_SESSION['languageId'];
    }
    else{
        $languageId='1';
    }

    if($_POST['site_type']!=""){
        $sql_details="select * from ".SITEMASTER." as SM ,".CATEGORIES." CA where SM.langId='".$languageId."' and SM.siteuserId='".$_SESSION['siteuserId']."' and SM.adcategoryId=CA.adcategoryId and SM.adSiteType='".$_POST['site_type']."' ";
    }
    elseif($_POST['show_status']!=""){
        $sql_details="select * from ".SITEMASTER." as SM ,".CATEGORIES." CA where SM.langId='".$languageId."' and SM.siteuserId='".$_SESSION['siteuserId']."' and SM.adcategoryId=CA.adcategoryId and SM.status='".$_POST['show_status']."' ";
    }
    else{
        $sql_details="select * from ".SITEMASTER." SM,".CATEGORIES." CA where SM.langId='".$languageId."' and SM.siteuserId='".$_SESSION['siteuserId']."' and SM.adcategoryId=CA.adcategoryId and SM.status='Y'";
    }
    $query_details=mysql_query($sql_details);
    $num=mysql_num_rows($query_details);
    $query_site_name=mysql_query("select adSiteName from adsite_master where siteuserId='".$_SESSION['siteuserId']."' and langId='".$languageId."'");
?>

<script type="text/javascript">
function delete_site(siteId){
    var site_delete = window.confirm("Are you sure to remove the selected site ?");
    if( site_delete == true )
    {
        document.adspaces.mode.value='delete_site';
        document.adspaces.siteId.value=siteId;
        document.adspaces.submit();
    }
}

function show(argu){
    document.adspaces.site_type.value=argu;
    document.adspaces.submit();
}

function show_status(argu){
    document.adspaces.show_status.value=argu;
    document.adspaces.submit();
}

function show_site_nane(argu1){
    document.adspaces.site_name.value=argu1;
    document.adspaces.submit();
}
function change_status(argu3){
    document.adspaces.Id.value=argu3;
    document.adspaces.mode.value="change_status";
    document.adspaces.submit();
}
</script>

<form name="adspaces" action="" method="POST">
<input type="hidden" name="site_type" value="">
<input type="hidden" name="show_status" value="">
<input type="hidden" name="mode" value="">
<input type="hidden" name="site_name" value="">
<input type="hidden" name="Id" value="">
<input type="hidden" name="siteId" value="">

<table width="90%" border="0" cellspacing="0" cellpadding="0">
    <tr>
        <td valign="top" align="center">
        <table width="98%" border="0" align="center" cellpadding="0" cellspacing="0">
        <tr>
            <td valign="top"></td>
            <td valign="top">
            <table width="100%" border="0" cellspacing="0" cellpadding="0">
            <tr>
                <td valign="top">
                    <table width="100%" border="0" cellspacing="0" cellpadding="0">
                    <tr>
                        <td width="11"><img src="images/PinkBorderTopLeft.jpg" alt="" width="11" height="11"></td>
                        <td class="PinkBoxTopBg"><img src="images/spacer.gif" alt="" width="10" height="11"></td>
                        <td width="11"><img src="images/PinkBorderTopRight.jpg" alt="" width="11" height="11"></td>
                    </tr>
                    </table>
                </td>
            </tr>
            <tr>
                <td class="PinkTwosideBorder" valign="top">
                <table width="100%" class="center" cellspacing="0" cellpadding="0">
                <tr>
                    <td align="left" valign="top">
                    <!-- start table  -->
                    <table id="spacesList" style="width:100%;margin-left:1px;position:relative" align="center" border="0" >
                    <tr>
                    <td colspan="2" align="center" class="sky font-18" style="padding-bottom:20px;">
                    <?php echo MY_WEBSITES; ?>
                    </td>
                    <?php
                    if($GLOBALS['err_msg']!="")
                    {
                    ?>
                    <tr>
                        <td colspan="2" align="center" class="ERR" style="padding-bottom:10px;">
                            <strong><?php echo $GLOBALS['err_msg'];?></strong>
                        </td>
                    </tr>
                    <?php
                    }
                    ?>
                    <tr>
                        <td style="text-align:left;white-space:nowrap;padding-bottom:10px;" colspan="2">
                        <span class="font-12 black advertise_tableTxt">
                            <?php echo SITE_TYPE; ?>:
                            <select id="adspaceType" name="adspace_type" class="InputBox" style="width: 150px;" maxlength="150">
                                <option value="">--Select--</option>
                                <option value="text" onclick="return show('MOBILE');"><?php echo MOBILE; ?></option>
                                <option value="banner" onclick="return show('WEB');"><?php echo WEB; ?></option>
                            </select>
                        </span>
                        &nbsp;
                        <span class="font-12 black advertise_tableTxt">
                            <?php echo STATUS; ?>:
                            <select id="adspaceType" name="adspace_type" class="InputBox" style="width: 150px;" maxlength="150">
                                <option value="">--Select--</option>
                                <option value="text" onclick="return show_status('Y');"><?php echo ACTIVE; ?></option>
                                <option value="banner" onclick="return show_status('N');"><?php echo BLOCK; ?></option>
                                <option value="banner" onclick="return show_status('P');"><?php echo PENDING; ?></option>
                            </select>
                        </span>
                        &nbsp;
                        <span class="font-12 black advertise_tableTxt">
                            <input type="button" value="Show all" onclick="javascript: window.location='all_websites.php';">
                        </span>
                        </td>
                    </tr>
                    <tr>
                    <td colspan="2">
                    <table width="100%" border="1"cellspacing="0" cellpadding="0">
                    <tr>
                    <td align="center">
                    <table width="100%" class="login_txt" cellspacing="1" cellpadding="0" border="0">
                    <tr style="background-color:gray">
                        <th class="listHeader" align="center" nowrap="true">
                            <strong><?php echo SITE_NAME; ?></strong>
                        </th>
                        <th class="listHeader" align="center" nowrap="true">
                            <?php echo CATEGORY; ?>
                        </th>
                        <th class="listHeader" align="center" nowrap="true">
                            <?php echo SITE_TYPE; ?>
                        </th>
                        <th class="listHeader" align="center" nowrap="true">
                            <?php echo URL; ?>
                        </th>
                        <th class="listHeader" align="center" nowrap="true">
                            <?php echo SITE_DESC; ?>
                        </th>
                        <th class="listHeader" align="center" nowrap="true">
                            <?php echo AD_SPACES; ?>
                        </th>
                        <th colspan="1" class="listHeader" align="center" nowrap="true"><?php echo STATUS; ?></th>
                        <th colspan="1" class="listHeader" align="center" nowrap="true">Delete</th>
                    </tr>
                    <?php
                    if($num>0)
                    {
                    $loop=0;
                    while($rec_details=mysql_fetch_array($query_details)){
                    $loop++;
                    if($loop%2 == 0){
                        $class1="normalActive2";
                        $class2="normal2";
                        $class3="normal2";
                        $class4="gray_sitename2";
                    }
                    else{
                        $class1="normalActive";
                        $class2="normal";
                        $class3="normal";
                        $class4="white_sitename2";
                    }

                    $sql_price="select count(*) from ".ADSPSCEMASTER." where adsiteId='".$rec_details['adsiteId']."' ";
                    $query_price=mysql_fetch_array(mysql_query($sql_price));
                    ?>

                    <tr onmouseover="this.className='<?php echo $class1;?>'" onmouseout="this.className='<?php echo $class2;?>'" class="<?php echo $class3;?>">
                        <td class="<?php echo $class4;?>" align="left"><a href="edit_websites.php?tab=sell_ads&subMenu=3&sid=<?php echo $rec_details['adsiteId'];?>" class="register_link"><?php echo $rec_details['adSiteName'];?></a></td>
                        <td class="<?php echo $class4;?>" align="left"><?php echo $rec_details['categoryName'];?></td>
                        <td class="<?php echo $class4;?>" align="left"><?php echo $rec_details['adSiteType'];?></td>
                        <td class="<?php echo $class4;?>" align="left"><?php echo $rec_details['adSiteUrl'];?></td>
                        <td class="<?php echo $class4;?>" align="left"><?php echo $rec_details['siteDescription'];?></td>
                        <td class="<?php echo $class4;?>" align="left"><?php echo $query_price[0];?></td>
                        <td align="left" class="<?php echo $class4;?>">
                        <?
                        $status=mysql_fetch_array(mysql_query("select status from ".SITEMASTER." where adsiteId='".$rec_details['adsiteId']."' "));
                        if($status['status']=='P'){
                        ?>
                            <font color="#CC0000">Pending</font>
                        <?
                        }
                        elseif($status['status']=='N'){
                        ?>
                        <a href="javascript:change_status('<?php echo $rec_details['adsiteId'];?>')" title="Activate Deactivate Status" class="register_link">
                        <font color="#CC0000">Block</font></a>
                        <? 	}
                        else
                        { ?>
                                <a href="javascript:change_status('<?php echo $rec_details['adsiteId'];?>')" title="Activate Deactivate Status" class="register_link"> <font color=\"#66CC00\">Active</font></a>
                        <?
                        }
                        ?>
                        </td>
                        <!--<td align="center"><img src="images/trashcan_icon.gif" alt="" onClick="delete_site('<?php echo $rec_details['adsiteId'];?>');"></td>-->
                        <td class="<?php echo $class4;?>" align="center"><img src="images/trashcan_icon.gif" alt="" onClick="delete_site('<?php echo $rec_details['adsiteId'];?>');"></td>
                    </tr>
                    <?php
                    }
                    } // end if
                    else
                    {
                    ?>
                    <tr><td colspan="10" align="center" class="font-12 black advertise_tableTxt"><?php echo NO_RECORD_FOUND; ?></TD></tr>
                    <?php
                    }
                    ?>
                    </table>
                    </td>
                    </tr>
</table>

   </td>
  </tr>
</table>

<!-- e table  -->

</td>
</tr>
</table></td>
                      </tr>
                      <tr>
                        <td><table width="100%" border="0" cellspacing="0" cellpadding="0">
                            <tr>
                              <td width="11"><img src="images/PinkBorderBottomLeft.jpg" alt="" width="11" height="11"></td>
                              <td class="PinkBoxBottomBg"><img src="images/spacer.gif" alt="" width="10" height="11"></td>
                              <td width="11"><img src="images/PinkBorderBottomRight.jpg" alt="" width="11" height="11"></td>
                            </tr>
                        </table></td>
                      </tr>
                    </table></td>
                    <td>&nbsp;</td>
                    </tr>
                </table></td>
              </tr>
            </table>
</form>
            
<?php
        //include("footer.php");
}
		?> 